import Cookies from "js-cookie";

const TokenKey = "l-Token";
const UserInfo = "l_userinfo";
const UserId = "l_userid";

export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token, expires) {
  return Cookies.set(TokenKey, token, {
    expires
  });
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

export function getUserId() {
  const userInfo = Cookies.get(UserId);
  return userInfo || "";
}

export function setUserId(userid) {
  return Cookies.set(UserId, userid || "");
}

export function getUserInfo() {
  const userInfo = Cookies.get(UserInfo);
  return userInfo ? JSON.parse(userInfo) : "";
}

export function setUserInfo(userinfo) {
  return Cookies.set(UserInfo, userinfo || "");
}

export function removeUserInfo() {
  return Cookies.remove(UserInfo);
}

export function clearCache() {
  removeToken();
  removeUserInfo();
}
